package com.iflytek.autoCompareTool.common;

import com.iflytek.autoCompareTool.service.Executor;
import com.iflytek.autoCompareTool.service.Monitor;
import org.apache.commons.lang3.StringUtils;

import java.util.Properties;
import java.util.concurrent.TimeUnit;

/**
 * @author llchen12
 * @date 2018/6/8
 */
public class Config {


    public static String RESULT_DIR = "D:/test/temp";

    public static String DOWNLOAD_URL = "http://172.16.154.185:8082/aiui-manager/tool/autotest/customtestResult?zipName=";

    public static String TOOL_ID = "tool_test";

    public static String URL_ENV_ONLINE = "http://athena.openspeech.cn/athena/iss?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";

    public static String URL_ENV_PRE = "http://192.168.86.153/athena/onlinepre?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";

    public static String URL_ENV_NLU_TEST = "http://192.168.86.153/athena/nlu_test?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";

    public static String URL_ENV_KCLOUD_CURRENT = "http://kcbj.openspeech.cn/service/iss?ver=2.0&method=query&flag=test&reqsrc=test";

    public static String URL_ENV_KCLOUD_MOVE_PK = "http://10.1.86.21:9668/athena?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";

    public static String URL_ENV_KCLOUD_MOVE_NLU = "http://10.1.86.21:9669/athena?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";

    public static String URL_ENV_ATHENA_MOVE = "http://172.16.154.88:5008/athena?ver=3.1&method=query&open.dialog=true&flag=test&reqsrc=test";


    //db配置

    /**
     * aiui_manager
     */
    public static String DB_AIUI_MANAGER_USERBANE = "root";

    public static String DB_AIUI_MANAGER_PAASORD = "imsp_vcloud";

    public static String DB_AIUI_MANAGER_URL = "jdbc:mysql://172.16.154.26:3306/aiui_manager?useSSL=false";

    public static String DB_AIUI_MANAGER_DRIVER = "com.mysql.jdbc.Driver";

    /**
     * kcloud_tool
     */
    public static String DB_KCLOUD_TOOL_USERBANE = "root";

    public static String DB_KCLOUD_TOOL_PAASORD = "startcloud";

    public static String DB_KCLOUD_TOOL_URL = "jdbc:mysql://192.168.86.19:3306/kcloud_tool?useSSL=false";

    public static String DB_KCLOUD_TOOL_DRIVER = "com.mysql.jdbc.Driver";

    /**
     * ovs2
     */
    public static String DB_OVS2_USERBANE = "root";

    public static String DB_OVS2_PAASORD = "imsp_vcloud";

    public static String DB_OVS2_URL = "jdbc:mysql://192.168.86.16:3306/ovs2?useSSL=false";

    public static String DB_OVS2_DRIVER = "com.mysql.jdbc.Driver";


    public static long MONITOR_FIXRATE_MILLISECONDS = 10000;

    public static long CHECKER_FIXRATE_MILLISECONDS = 5000;

    public static int WORKER_THREAD_CORESIZE = 5;

    public static int WORKER_THREAD_MAXSIZE = 10;

    public static int PROCESSOR_THREAD_CORESIZE = 5;

    public static int PROCESSOR_THREAD_MAXSIZE = 10;


    public static void init(Properties conf) {
        if (conf != null && !conf.isEmpty()) {
            if (StringUtils.isNotBlank(conf.getProperty("download.url"))) {
                DOWNLOAD_URL = conf.getProperty("download.url");
            }

            if (StringUtils.isNotBlank(conf.getProperty("result.dir"))) {
                RESULT_DIR = conf.getProperty("result.dir");
            }

            if (StringUtils.isNotBlank(conf.getProperty("tool.id"))) {
                TOOL_ID = conf.getProperty("tool.id");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.online"))) {
                URL_ENV_ONLINE = conf.getProperty("env.online");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.pre"))) {
                URL_ENV_PRE = conf.getProperty("env.pre");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.nlu_test"))) {
                URL_ENV_NLU_TEST = conf.getProperty("env.nlu_test");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.athena_move"))) {
                URL_ENV_ATHENA_MOVE = conf.getProperty("env.athena_move");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.kcloud_current"))) {
                URL_ENV_KCLOUD_CURRENT = conf.getProperty("env.kcloud_current");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.kcloud_move_nlu"))) {
                URL_ENV_KCLOUD_MOVE_NLU = conf.getProperty("env.kcloud_move_nlu");
            }
            if (StringUtils.isNotBlank(conf.getProperty("env.kcloud_move_pk"))) {
                URL_ENV_KCLOUD_MOVE_PK = conf.getProperty("env.kcloud_move_pk");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.aiui_manager.username"))) {
                DB_AIUI_MANAGER_USERBANE = conf.getProperty("db.aiui_manager.username");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.aiui_manager.password"))) {
                DB_AIUI_MANAGER_PAASORD = conf.getProperty("db.aiui_manager.password");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.aiui_manager.url"))) {
                DB_AIUI_MANAGER_URL = conf.getProperty("db.aiui_manager.url");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.aiui_manager.driver"))) {
                DB_AIUI_MANAGER_DRIVER = conf.getProperty("db.aiui_manager.driver");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.kcloud_tool.username"))) {
                DB_KCLOUD_TOOL_USERBANE = conf.getProperty("db.kcloud_tool.username");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.kcloud_tool.password"))) {
                DB_KCLOUD_TOOL_PAASORD = conf.getProperty("db.kcloud_tool.password");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.kcloud_tool.url"))) {
                DB_KCLOUD_TOOL_URL = conf.getProperty("db.kcloud_tool.url");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.kcloud_tool.driver"))) {
                DB_KCLOUD_TOOL_DRIVER = conf.getProperty("db.kcloud_tool.driver");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.ovs2.username"))) {
                DB_OVS2_USERBANE = conf.getProperty("db.ovs2.username");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.ovs2.password"))) {
                DB_OVS2_PAASORD = conf.getProperty("db.ovs2.password");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.ovs2.url"))) {
                DB_OVS2_URL = conf.getProperty("db.ovs2.url");
            }
            if (StringUtils.isNotBlank(conf.getProperty("db.ovs2.driver"))) {
                DB_OVS2_DRIVER = conf.getProperty("db.ovs2.driver");
            }
            if (StringUtils.isNotBlank(conf.getProperty("monitor.fixedRateInMillisecond"))) {
                MONITOR_FIXRATE_MILLISECONDS = Long.parseLong(conf.getProperty("monitor.fixedRateInMillisecond"));
            }
            if (StringUtils.isNotBlank(conf.getProperty("checker.fixedRateInMillisecond"))) {
                CHECKER_FIXRATE_MILLISECONDS = Long.parseLong(conf.getProperty("checker.fixedRateInMillisecond"));
            }
            if (StringUtils.isNotBlank(conf.getProperty("workThread.coreSize"))) {
                WORKER_THREAD_CORESIZE = Integer.parseInt(conf.getProperty("workThread.coreSize"));
            }
            if (StringUtils.isNotBlank(conf.getProperty("workThread.maxSize"))) {
                WORKER_THREAD_MAXSIZE = Integer.parseInt(conf.getProperty("workThread.maxSize"));
            }
            if (StringUtils.isNotBlank(conf.getProperty("processThread.coreSize"))) {
                PROCESSOR_THREAD_CORESIZE = Integer.parseInt(conf.getProperty("processThread.coreSize"));
            }
            if (StringUtils.isNotBlank(conf.getProperty("processThread.maxSize"))) {
                PROCESSOR_THREAD_MAXSIZE = Integer.parseInt(conf.getProperty("processThread.maxSize"));
            }
        }
        //加载数据源
        DBManager.getInstance();
        //启动监视守护线程
        Executor.getInstance().getMonitorScheduler()
                .scheduleAtFixedRate(new Monitor(), 0L, MONITOR_FIXRATE_MILLISECONDS, TimeUnit.MILLISECONDS);
    }
}
